<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function gams(index){
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          Math.random() > 0.1 ? resolve(index + 'success') : reject(index + 'fail')
        }, 1000)
      })
    }
    gams(1).then(res => {
      console.log(res);
      return gams(2)
    }).then(res => {
      console.log(res);
      return gams(3)
    }).then(res => {
      console.log(res);
    })

    async function run(){
      try{
        const key1 = await gams(1);
        console.log(key1);
        const key2 = await gams(2);
        console.log(key2);
        const key3 = await gams(3);
        console.log(key3);
        return [key1,key2,key3];
      }catch(error){
        console.log(error);
        return Promise.reject(error)
      }
    }
    run().then(res => {
      console.log(res);
    }).catch(error => {
      console.log(error);
    })
  </script>
</body>
</html>